<?php
//生成时间2023-03-30 17:22
class tuser{
    static private $id=NULL;//编号
    static public function Set_id($id){
        if(!is_numeric($id)){
            return "编号的输入必须是数字";
        }
        self::$id=addslashes($id);
        return 1;
    }
    static private $s_name=NULL;//姓名
    static public function Set_s_name($s_name){
        if(strlen($s_name)<1 || strlen($s_name)>90){
            return "姓名的输入字数不在指定范围1~90";
        }
        self::$s_name=addslashes($s_name);
        return 1;
    }
    static private $s_sex=NULL;//性别
    static public function Set_s_sex($s_sex){
        if(strlen($s_sex)<1 || strlen($s_sex)>10){
            return "性别的输入字数不在指定范围1~10";
        }
        if(!in_array($s_sex,array("男","女"))){
            return "性别的输入必须是[男,女]";
        }
        self::$s_sex=addslashes($s_sex);
        return 1;
    }
    static public function Add($db){
        $params=array();
        $sql="insert into t_user_t(";
        $sql.=self::$id!=NULL?"id,":'';
        $sql.=self::$s_name!=NULL?"s_name,":'';
        $sql.=self::$s_sex!=NULL?"s_sex,":'';
        $sql=trim($sql,',');
        $sql.=") values (";
        if(self::$id!=NULL){
            $sql.="?,";
            array_push($params,self::$id);
        }
        if(self::$s_name!=NULL){
            $sql.="?,";
            array_push($params,self::$s_name);
        }
        if(self::$s_sex!=NULL){
            $sql.="?,";
            array_push($params,self::$s_sex);
        }
        $sql=trim($sql,',');
        $sql.=");";
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Edit($db){
        $params=array();
        $sql="update t_user_t set ";
        if(self::$s_name!=NULL){
            $sql.=" s_name=?,";
            array_push($params,self::$s_name);
        }
        if(self::$s_sex!=NULL){
            $sql.=" s_sex=?,";
            array_push($params,self::$s_sex);
        }
        $sql=trim($sql,',');
        $sql.=" where 1=1";
        if(self::$id!=NULL){
            $sql.=" and id=?";
            array_push($params,self::$id);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Delete($db){
        $params=array();
        $sql="delete from t_user_t";
        $sql.=" where 1=1";
        if(self::$id!=NULL){
            $sql.=" and id=?";
            array_push($params,self::$id);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Select(){
        $sql="select * from t_user_t";
        return $sql;
    }
}
?>